<template>
  <t-adaptive-page
      v-loading="state.loading"
      class="menu_mange"
      tableTitle="收款计划确认单列表"
      row-key="path"
      isCopy
      show-summary
      ref="tAdaptivePageRef"
      isExpansion
      :isTTableSelfFilling="false"
      :isShowPagination="false"
      columnSetting
      :table="state.table"
      :columns="state.table.columns"
      isShowWidthSize
      :opts="opts"
      :widthSize="4"
      @submit="conditionEnter"
      @radio-change="selecUpdateChange"
  >
    <template #CreateDate="{scope}">
      <div>{{ parseTime(scope.row.CreateDate) }}</div>
    </template>

    <template #toolbar>
      <div v-if="state.selectedRow">
        <el-button type="primary"  @click="handlEedit(state.selectedRow)"  v-if="(['0'].includes(state.selectedRow.State) || state.selectedRow.State===null) && checkPermission('修改', state.roleList)">编辑</el-button>
        <el-button type="primary"  @click="deleteHandles(state.selectedRow)" v-if="(['0'].includes(state.selectedRow.State) || state.selectedRow.State===null) && checkPermission('删除', state.roleList)" >删除</el-button>
        <el-button type="primary"  @click="handlCheck(state.selectedRow,'2')" v-if="(['0'].includes(state.selectedRow.State) || state.selectedRow.State===null) && checkPermission('审核', state.roleList)">审核</el-button>
        <el-button type="primary"  @click="handlCheck(state.selectedRow, '0')" v-if="['2'].includes(state.selectedRow.State) && checkPermission('弃审', state.roleList)">弃审</el-button>
      </div>
      <div v-else style="color:red">
        选择数据后显示操作按钮
      </div>
    </template>

    <template #JobNum="{ scope }">
      <div>
        <el-link
            link
            @click="viewCheck(scope.row)"
            type="primary"
        >{{ scope.row.JobNum }}</el-link>
      </div>
    </template>



    <template #State="{scope}">
      <el-tag type="info" v-if="scope.row.State=='0'">开立</el-tag>
      <el-tag type="success" v-if="scope.row.State=='2'">已审核</el-tag>
      <el-tag type="primary" v-if="scope.row.State=='1'">送审中</el-tag>
      <el-tag type="danger" v-if="scope.row.State=='3'">已关闭</el-tag>
    </template>

    <template #footerBtn>
      <el-button type="danger" @click="addHandle()" v-if="checkPermission('新增', state.roleList)">新增</el-button>
<!--      <el-button type="danger" @click="deleteHandles" :disabled="!state.ids.length" v-if="checkPermission('删除', state.roleList)">删除</el-button>-->

      <el-button type="primary" @click="tAdaptivePageRef.TQueryConditionPage.checkHandle()">查询</el-button>
      <el-button type="danger" @click="tAdaptivePageRef.TQueryConditionPage.resetHandle()">重置</el-button>
    </template>

  </t-adaptive-page>

  <!--  新增 / 修改-->
  <el-dialog :title="state.title" width="60%" v-model="state.dialogSelectEnt" draggable :close-on-click-modal="false" @close="closeDialog">
    <el-form ref="formRef" :model="state.formData" :rules="state.rules" label-position="right" :disabled="!state.isEdit">
      <el-row :gutter="10">
        <el-col :span="6">
          <el-form-item label="工作号" prop="JobNum">
            <JobNumberDropdown
                :isUseGlobalData="false"
                v-model="state.formData.JobNum"
                @change="updateContarctInfo"
                :contract-list="cubasdoc.contractList"
            />
          </el-form-item>

<!--          <el-form-item label="合同号" prop="ContractNum">-->
<!--            <el-select-->
<!--                v-model="state.formData.ContractNum"-->
<!--                filterable-->
<!--                remote-->
<!--                reserve-keyword-->
<!--                @change="updateContarctInfo"-->
<!--                placeholder="请选择合同号"-->
<!--                remote-show-suffix-->
<!--            >-->
<!--              <el-option-->
<!--                  v-for="item in cubasdoc.contractList"-->
<!--                  :key="item.ContractNum"-->
<!--                  :label="item.ProjectName"-->
<!--                  :value="item.ContractNum">-->
<!--                <span style="float: left">{{ item.ProjectName }}</span>-->
<!--                <span style="float: right;color: var(&#45;&#45;el-text-color-secondary);font-size: 13px;">【{{item.ContractNum}}】</span>-->
<!--              </el-option>-->
<!--            </el-select>-->
<!--          </el-form-item>-->
        </el-col>
        <el-col :span="6">
          <el-form-item label="项目名称" prop="EntryName">
            <el-input v-model="state.formData.EntryName" disabled placeholder="请输入项目名称" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="合同号" prop="ContractNum">
            <el-input v-model="state.formData.ContractNum" disabled placeholder="请输入合同号" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="6">
          <el-form-item label="客户名称" prop="CustName">
            <el-input v-model="state.formData.CustName" placeholder="请输入客户名称" disabled />
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="合同金额" prop="ContractAmount">
            <el-input v-model="state.formData.ContractAmount" placeholder="请输入合同金额" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="订单金额" prop="OrderAmount">
            <el-input v-model="state.formData.OrderAmount" placeholder="请输入订单金额" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="6">
          <el-form-item label="发货金额" prop="FHAmount">
            <el-input v-model="state.formData.FHAmount" placeholder="请输入发货金额" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="发票金额" prop="FPAmount">
            <el-input v-model="state.formData.FPAmount" placeholder="请输入发票金额" clearable />
          </el-form-item>
        </el-col>
        <!--          <el-col :span="6">-->
        <!--            <el-form-item label="应收款税率" prop="YSKRatio">-->
        <!--              <el-input v-model="state.formData.YSKRatio" placeholder="请输入应收款税率" clearable />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <el-col :span="6">
          <el-form-item label="应收款金额" prop="YSKAmount">
            <el-input v-model="state.formData.YSKAmount" placeholder="请输入应收款金额" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="10">
          <el-form-item label="验收日期" prop="YSDate">
            <!-- <el-input v-model="state.formData.YSDate" placeholder="请输入验收日期" clearable /> -->
            <t-date-picker v-model="state.formData.YSDate" :size="size" @change="change($event, 'date', state.formData.YSDate)" />
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="应收款时间" prop="YSKDate">
            <!-- <el-input v-model="state.formData.YSKDate" placeholder="请输入应收款时间" clearable /> -->
            <t-date-picker v-model="state.formData.YSKDate" :size="size" @change="change($event, 'date', state.formData.YSKDate)" />
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="收款类型" prop="Type">
            <el-select v-model="state.formData.Type">
              <el-option label="质保金" value="质保金">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>
    <!--      <t-layout-page-item>-->
    <!--        <t-table-->
    <!--            title="明细"-->
    <!--            ref="singleEdit"-->
    <!--            :table="state.clumTable"-->
    <!--            :columns="state.clumTable.columns"-->
    <!--            :isShowPagination="false"-->
    <!--            :listTypeInfo="state.clumTable.listTypeInfo"-->
    <!--        >-->
    <!--          <template #toolbar>-->
    <!--            <t-select-table-->
    <!--                ref="selectTable_t"-->
    <!--                :table="state.editTable"-->
    <!--                :columns="state.editTable.columns"-->
    <!--                :max-height="400"-->
    <!--                multiple-->
    <!--                :defaultSelectVal="state.defaultSelectVal"-->
    <!--                @selectionChange="selectionChange"-->
    <!--                :keywords="{ label: 'TermContent', value: 'ConTKId' }"-->
    <!--            ></t-select-table>-->
    <!--            <el-button style="margin-left: 15px" type="primary" @click="addToTable">确认选择</el-button>-->
    <!--          </template>-->
    <!--        </t-table>-->

    <!--      </t-layout-page-item>-->

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="submitForm" v-if="state.isEdit">确 定</el-button>
      </div>
    </template>
  </el-dialog>

</template>

<script setup lang="tsx">
import {computed, onMounted, reactive, ref, toRefs, unref, watch} from "vue"
import {selcetDataList,saveSKJH,getOneSKJH,delSKJH,GetOneHTSKJH2} from "@/api/payment_plan"
import {getTHFH,ApproveDocument,userRole} from "@/api/base"
import {parseTime,checkPermission} from "@/utils/util";
import {cubasdocStore} from "@/stores/modules/cubasdoc";
import {ElMessage} from "element-plus";
import JobNumberDropdown from "@/components/JobNumberDropdown/index.vue";

const tAdaptivePageRef: any = ref(null)

const size = ref("default")

const handlCheck = async (row: any,status: any)  => {
  //调用查询合同详细信息
  const ids = [row.Id];
  let data={
    "Ids": ids,  //单据id
    "Type":"SKJH",  //类型 HTLR 合同录入 TDYS 通电验收  FHYS 发货验收  JSD 结算单  SKJH 收款计划 SKD 收款单 YKP 预收款发票
    "State":status,
  }
  await ApproveDocument(data);
  ElMessage.success("审核成功")
  await getData()
}


const cubasdoc = cubasdocStore()

const selectTable_t= ref(null)
const handlEedit = async (row: any)  => {
  let {Data} = await getOneSKJH({id:row.Id})
  state.formData = Data.Main
  const slist = [];
  if (Data?.SubLists){
      //赋值合同明细转换
    for(var i=0;i<Data.SubLists.length;i++){
      const subdata =
      {
          "ConTKId":Data.SubLists[i].Id, //条款id
          "TermContent":Data.SubLists[i].Content, //条款id
          "FHAmount":Data.SubLists[i].FHAmount, //发货金额
          "FPAmount":Data.SubLists[i].FPAmount, //发票金额
          "YSKRatio":Data.SubLists[i].YSKRatio, //应收比例
          "YSKAmount":Data.SubLists[i].YSKAmount,//应收款
          "YSDate":Data.SubLists[i].YSDate, //验收时间
          "YSKDate":Data.SubLists[i].YSKDate, //应收款日期
          "Remark":Data.SubLists[i].Remark
      }
      slist.push(subdata);
    }
  }
  state.clumTable.data = slist;
  //过滤合同
  let contractInfo = cubasdoc.contractList.find((item: any) => item.ContractNum == row.ContractNum)
  if (contractInfo){
    await findContractInfo(contractInfo.Id)
    state.defaultSelectVal = Data.SubLists.map((item: any) => item.ConTKId)
    state.dialogSelectEnt = true
  }

  state.isEdit = true
  state.title = '编辑'
}

const viewCheck = async (row: any)  =>{
  let {Data} = await getOneSKJH({id:row.Id})
  state.formData = Data.Main
  const slist = [];
  if (Data?.SubLists){
    //赋值合同明细转换
    for(var i=0;i<Data.SubLists.length;i++){
      const subdata =
          {
            "ConTKId":Data.SubLists[i].Id, //条款id
            "TermContent":Data.SubLists[i].Content, //条款id
            "FHAmount":Data.SubLists[i].FHAmount, //发货金额
            "FPAmount":Data.SubLists[i].FPAmount, //发票金额
            "YSKRatio":Data.SubLists[i].YSKRatio, //应收比例
            "YSKAmount":Data.SubLists[i].YSKAmount,//应收款
            "YSDate":Data.SubLists[i].YSDate, //验收时间
            "YSKDate":Data.SubLists[i].YSKDate, //应收款日期
            "Remark":Data.SubLists[i].Remark
          }
      slist.push(subdata);
    }
  }
  state.clumTable.data = slist;
  //过滤合同
  let contractInfo = cubasdoc.contractList.find((item: any) => item.ContractNum == row.ContractNum)
  if (contractInfo){
    await findContractInfo(contractInfo.Id)
    state.defaultSelectVal = Data.SubLists.map((item: any) => item.ConTKId)
    state.dialogSelectEnt = true
  }
  state.isEdit = false
  state.title = '详情'
}

const handleDelete = (row: any) => {

  state.clumTable.data.splice(state.clumTable.data.indexOf(row), 1)
}

// 数量change事件
const numChange = (val, prop, scope) => {


}


const change = (event, type, value) => {

}

//表格配置
const state: any = reactive({
  roleList:[],
  isEdit: false,
  queryData: {
    cCode:null,
    JobNum: null, // 登录名
    ContractNum: null, // 用户状态
    CreateFrom: null,
    CreateTo: null,
    CreateBy: null
  },
  table: {
    border: true,
    // 接口返回数据
    data: [],
    firstColumn: { type: "radio", fixed: true },
    // 表头数据
    columns: [
      { prop: "JobNum", label: "工作号", minWidth: 120,fixed: 'left',slotName: "JobNum" },
      { prop: "cCode", label: "计划单号", minWidth: 120,fixed: 'left' },
      { prop: "EntryName", label: "项目名称", minWidth: 160 },
      { prop: "ContractNum", label: "合同号",minWidth: 120},
      { prop: 'State', label: '状态', minWidth: 120, slotName: 'State' },
      { prop: "CustName", label: "客户名称",minWidth: 160},
      { prop: "ContractAmount", label: "合同金额",minWidth: 120},
      { prop: "OrderAmount", label: "订单金额",minWidth: 120},
      { prop: "FHAmount", label: "发货金额",minWidth: 120},
      { prop: "FPAmount", label: "发票金额",minWidth: 120},
      { prop: "YSKRatio", label: "应收款税率",minWidth: 120},
      { prop: "YSKAmount", label: "应收款金额",minWidth: 120},
      { prop: "YSDate", label: "应收日期", minWidth: 220,slotName: "YSDate"},
      { prop: "YSKDate", label: "收款日期", minWidth: 220,slotName: "YSKDate"},
      { prop: "CreateDate", label: "建单日期", minWidth: 220,slotName: "CreateDate"},
      { prop: "CreateBy", label: "建单人", minWidth: 220 },
      { prop: "ApproveDate", label: "审核日期", minWidth: 220,slotName: "ApproveDate"},
      { prop: "ApproveBy", label: "审核人", minWidth: 220 },
    ],
  },
  loading:false,
  title: "新增收款计划单",
  dialogSelectEnt:false,
  formData: {
    JobNum: null, // 工作号
    ContractNum: null, // 合同号
    cCode: null,
    CustName: null,
    YSDate: ref(),
    YSKDate: ref(),
    CreateBy: null,
    ContractAmount: null,
    OrderAmount: null,
    EntryName:null,

   },
  coseData:[],

  clumTable: {
    border: true,
    firstColumn: { type: "selection" },
    // 接口返回数据
    data: [],
    // 表头数据
    columns: [
      // {
      //   prop: "ConTKId",
      //   label: "条款id",
      //   isShowHidden: true
      // },
      {
        prop: "TermContent",
        label: "条款",
        width:150,
      },
      {
        prop: "FHAmount",
        label: "发货金额",
        width:150,
        canEdit: true,
        configEdit: {
          label: "发货金额",
          type: "input",
          editComponent: "el-input",
          eventHandle: {
            change: ({ val, prop, scope }) => numChange(val, prop, scope)
          }
        }
      },
      {
        prop: "FPAmount",
        label: "发票金额",
        width:150,
        canEdit: true,
        configEdit: {
          label: "发票金额",
          type: "input",
          editComponent: "el-input",
          eventHandle: {
            change: ({ val, prop, scope }) => numChange(val, prop, scope)
          }
        }
      },
      {
        prop: "YSKRatio",
        label: "应收比例",
        width:150,
        canEdit: true,
        configEdit: {
          append: "%",
          label: "应收比例",
          type: "input",
          editComponent: "el-input",
          eventHandle: {
            change: ({ val, prop, scope }) => numChange(val, prop, scope)
          }
        }
      },
      {
        prop: "YSKAmount",
        label: "应收款",
        width:150,
        canEdit: true,
        configEdit: {
          label: "应收款",
          type: "input",
          editComponent: "el-input",
          eventHandle: {
            change: ({ val, prop, scope }) => numChange(val, prop, scope)
          }
        }
      },{
        prop: "Remark",
        label: "备注",
        width:150,
        canEdit: true,
        configEdit: {
          label: "备注",
          type: "input",
          editComponent: "el-input",
          eventHandle: {
            change: ({ val, prop, scope }) => numChange(val, prop, scope)
          }
        }
      },

    ],
    listTypeInfo: {
      furnaceLayerList: [
        {
          label: "上层",
          key: "1"
        },
        {
          label: "中层",
          key: "2"
        },
        {
          label: "下层",
          key: "3"
        }
      ]
    },
    operator: [
      {
        text: "删除",
        fun: handleDelete
      }
    ],
    // 操作列样式
    operatorConfig: {
      fixed: "right", // 固定列表右边（left则固定在左边）
      width: 200,
      label: "操作"
    }
  },
  editTable: {
    border: true,
    firstColumn: { type: "selection" },
    // 接口返回数据
    data: [],
    // 表头数据
    columns: [
      // {
      //   prop: "ConTKId",
      //   label: "条款id",
      //   isShowHidden: true
      // },
      {
        prop: "TermContent",
        label: "条款",

      },
      {
        prop: "FHAmount",
        label: "发货金额",

      },
      {
        prop: "FPAmount",
        label: "发票金额",
        width:150,

      },
      {
        prop: "YSKRatio",
        label: "应收比例",
        width:150,
      },
      {
        prop: "YSKAmount",
        label: "应收款",
        width:150,

      },{
        prop: "Remark",
        label: "备注",
        width:150,
      },

    ],
    listTypeInfo: {
      furnaceLayerList: [
        {
          label: "上层",
          key: "1"
        },
        {
          label: "中层",
          key: "2"
        },
        {
          label: "下层",
          key: "3"
        }
      ]
    },
    operator: [
      {
        text: "删除",
        fun: handleDelete
      }
    ],
    // 操作列样式
    operatorConfig: {
      fixed: "right", // 固定列表右边（left则固定在左边）
      width: 200,
      label: "操作"
    }
  },

  rules:{
    // ContractNum: [
    //   { required: true, message: '请选择合同号', trigger: 'change' },
    // ],
    EntryName: [
      { required: true, message: '请输入项目名称', trigger: 'change' },
    ],
    JobNum: [
      { required: true, message: '请输入工作号', trigger: 'blur' },
    ],
  },
  defaultSelectVal:[],
  ids:[],
  selectedRow:null

})




//表单配置
const opts = ref({
  JobNum: {
    label: "工作号",
    comp: "el-input"
  },
  cCode: {
    label: "计划单号",
    comp: "el-input"
  },
  ContractNum: {
    label: "合同号",
    comp: "el-input"
  },
  EntryName: {
    label: "项目名称",
    comp: "el-input"
  },
  CreateFrom: {
    label: "制单日期",
    comp: "t-date-picker",
    span: 2,
    bind: {
      type: "daterange"
    }
  },

  CreateBy: {
    label: "建单人",
    comp: "el-input"
  },
})

//选择项
const cusoptions = ref([])


// 最终参数获取
const getQueryData = computed(() => {
  const { cCode,JobNum, ContractNum, CreateFrom, CreateBy } = toRefs(
      state.queryData
  )
  return {
    cCode: cCode.value,
    JobNum: JobNum.value,
    ContractNum: ContractNum.value,
    CreateBy: CreateBy.value,
    CreateFrom: CreateFrom.value && CreateFrom.value[0] ? CreateFrom.value[0] : null,
    CreateTo: CreateFrom.value && CreateFrom.value[1] ? CreateFrom.value[1] : null,
    //IsQS: IsQS.value,
  }
})

// 点击查询按钮
const conditionEnter = (data: any) => {

  state.queryData = data

  getData()
}

//页面加载查询后端数据
onMounted(() => {
  getData()
  initRoleList()
})

// 获取数据
const getData = async () => {
  state.loading = true
  let data=await selcetDataList(getQueryData.value);
  state.table.data = data;
  // if (data.Code==='OK'){
  //   state.table.data = data.Data
  // }
  state.loading = false
}

//过滤单位
const cnvbasdocMethod = (query) => {
  if (query) {
    state.loading = true
    setTimeout(() => {
      state.loading = false

      cusoptions.value = cubasdoc.data.filter((its) => {
        return (its.cCusCode.toLowerCase().includes(query.toLowerCase()) || its.ccusabbname.toLowerCase().includes(query.toLowerCase()))
      })
    }, 200)
  } else {
    cusoptions.value = []
  }
}

function updateContarctInfo (contractInfo) {
  //查询过滤合同信息
  // let contractInfo = cubasdoc.contractList.find(item=> item.JobNum===e);
  if (contractInfo){
    //赋值项目名称
    state.formData.EntryName = contractInfo?.ProjectName;
    state.formData.JobNum = contractInfo?.JobNum;
    state.formData.ContractAmount = contractInfo?.ContractAmount;
    state.formData.OrderAmount = contractInfo?.ContractAmount;
    state.formData.ContractId = contractInfo?.Id;
    state.formData.CustName = contractInfo?.CustName;
    state.formData.ContractNum = contractInfo?.ContractNum;
    //调用查询合同详细信息
    findContractInfo(contractInfo.Id)

    //查询带出开票等金额
    findThfh(contractInfo.Id)
  }
}

//查询带出开票等金额
async function findThfh (id) {
  let {Data}=await getTHFH({Id: id})

  if (Data){
    state.formData.FHAmount = Data.FHAmount;
    state.formData.FPAmount = Data.FPAmount;
    state.formData.YSKAmount = Data.YSKAmount;
  }
}


//查询合同详细信息
async function findContractInfo (id) {
  let {Data}=await GetOneHTSKJH2({id: id})

  const slist = [];
  if (Data?.TremZF2){
      //赋值合同明细转换
    for(var i=0;i<Data.TremZF2.length;i++){
      const subdata =
      {
          "Id":null,
          "MId":null,
          "ConTKId":Data.TremZF2[i].Id, //条款id
          "TermContent":Data.TremZF2[i].TermContent, //条款id
          "FHAmount":null, //发货金额
          "FPAmount":null, //发票金额
          "YSKRatio":Data.TremZF2[i].Ratio, //应收比例
          "YSKAmount":Data.TremZF2[i].Amount,//应收款
          "YSDate":null, //验收时间
          "YSKDate":null, //应收款日期
          "Remark":null
      }
      slist.push(subdata);
    }
    //赋值合同明细
    state.editTable.data = slist;
    //赋值合同明细
    // state.editTable.data = Data.SubList

  }


}


//打开新增窗口
function addHandle() {
  reset()
  state.formData = {
    YSDate: parseTime(new Date(), "{y}-{m}-{d}"),
    YSKDate: parseTime(new Date(), "{y}-{m}-{d}"),
  }
  state.dialogSelectEnt = true
  state.isEdit = true
  state.title = '新增'
}

//关闭弹窗
function closeDialog() {
  state.dialogSelectEnt = false
  reset()
}

// 添加数据条数
const num = ref(1)
const singleEdit: any = ref(null)

// 添加数据
const add = () => {
  if (num.value > 0) {
    for (let i = 0; i < num.value; i++) {
      state.editTable.data.push({})
    }
  }
}
// 重置表单
const reset = () => {
  state.formData = {}
  state.coseData= []
  state.clumTable.data=[]
  state.defaultSelectVal=[]
  state.editTable.data=[]
  selectTable_t.value?.clear()
  singleEdit.value?.resetFields()
}

//下拉表格选择数据
const selectionChange = (e) => {
  state.coseData = e

}

//下拉表格选择数据
const selecUpdateChange = (e) => {
  state.selectedRow = e
}


//选择标的
const addToTable = () => {

  if (state.coseData.length<=0){
    ElNotification.warning({
      title: '提示',
      message: '请选择标的',
      offset: 200,
    })
    return
  }


  state.coseData.forEach(item=>{

    //相同数据不能添加
    if (state.clumTable.data.find(item1=>item1.ConTKId===item.ConTKId || item1.ConTKId===item.ConTKId)){
      ElNotification.warning({
        title: '提示',
        message: item.CinvName+'已存在，请勿重复添加',
        offset: 200,
      })
      return
    }
    let Qty ={
      ...item,
      Qty:item.Quantity,
      ConSubId: item.Id
    }
    state.clumTable.data.push(Qty)
  })
}




//校验表单需要定义ref
let formRef =ref({})
// 提交表单
function submitForm() {
  //校验提交表单
  formRef.value.validate(async (vaild) => {
    if (vaild){
      // if (state.clumTable.data.length<=0){
      //   return ElMessage({
      //     message: '请选择标的',
      //     type: 'warning'
      //   })
      //   return
      // }
      let data={
        Main: {
          ...state.formData,
          State: '0',
        },
        //SubList:state.clumTable.data
        SubList:[]
      }

     let res= await saveSKJH(data)
      if (res.Code==='OK'){
        ElNotification.success({
          title: '提示',
          message: '保存成功',
          offset: 200,
        })
        closeDialog()
        await getData()

      }else{
        ElNotification.success({
          title: '提示',
          message: res.Result,
          offset: 200,
        })

      }

    }
  })


}


//删除表单
function deleteHandles(row) {

  const ids = row.Id ? [row.Id] : state.ids;


  ElMessageBox.confirm(
      '请仔细核对数据，删除后无法恢复！',
      '审核提示',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then(() => {
        delSKJH({Ids:ids})
        ElNotification.success({
          title: '提示',
          message: '删除成功',
          offset: 200,
        })

        getData()
      })
      .catch(() => {

      })


}

const initRoleList = async () => {
  let res = await userRole({ VT_ID: '收款计划确认单' })
  state.roleList = res.items
}


</script>
